﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Specialized;
using Controls;

public partial class widgets_AlbumList_edit : WidgetEditBase
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}

	protected override void OnPreRender(EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			//load current settings
			StringDictionary settings = GetSettings();
			string selectedItems = null;
			if (settings.ContainsKey("albumlist"))
			{
				selectedItems = settings["albumlist"];
			}

			//Assign selected categories
			if (!string.IsNullOrEmpty(selectedItems))
			{
				AlbumTree cTree = AlbumSelector1.FindControl("albumSelector") as AlbumTree;
				HiddenField cTreeHid = AlbumSelector1.FindControl("albumSelectorHid") as HiddenField;
				if (cTree != null)
				{
					cTree.SelectedItems = selectedItems;
					cTreeHid.Value = selectedItems;
				}
			}

		}
		base.OnPreRender(e);
	}

	#region base implementation
	public override void Save()
	{
		//Get selected categories
		HiddenField cTreeHid = AlbumSelector1.FindControl("albumSelectorHid") as HiddenField;
		if (cTreeHid != null)
		{
			var selectedItems = cTreeHid.Value;
			//save the selected values
			StringDictionary settings = GetSettings();
			settings["albumlist"] = selectedItems;
			SaveSettings(settings);
		}
	}
	#endregion
}
